package edu.scnu.fans.fingertip.user.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import edu.scnu.fans.fingertip.user.input.UserAddressDto;
import lombok.Data;

import java.time.Instant;

/**
 * 用户地址表
 */
@Data
@TableName("user_address")
public class UserAddress {

    @TableId(type = IdType.AUTO)
    private Long id;

    private Instant created;
    private Instant updated;
    private boolean deleted;

    /** 用户id */
    private Long userId;
    /** 收件人 */
    private String receiver;
    /** 收件人手机号 */
    private String mobile;
    /** 省份 */
    private String province;
    /** 城市 */
    private String city;
    /** 区县 */
    private String district;
    /** 详细地址 */
    private String addressDetail;
    /** 是否默认地址 */
    private Boolean defaultAddress;

    UserAddress() {
    }

    public UserAddress(Long userId) {
        this.userId = userId;
    }

    /**
     * 更新数据
     */
    public void update(UserAddressDto dto) {
        receiver = dto.getReceiver();
        mobile = dto.getMobile();
        province = dto.getProvince();
        city = dto.getCity();
        district = dto.getDistrict();
        addressDetail = dto.getAddressDetail();
    }

    public UserAddressDto transferToOutput() {
        return new UserAddressDto(id, receiver, mobile, province, city, district, addressDetail, defaultAddress);
    }

}
